#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e5 + 10;

int e[N], ne[N], h[N], w[N], idx;
int n, m, weight;
int node[110];
bool st[N];
vector<vector<int>> res;
vector<int> path;

void add(int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

void dfs(int u, int sum) {
    st[u] = true;
    if (sum == weight && h[u] == -1) {
        res.push_back(path);
        return ;
    }

    for (int i = h[u]; i != -1; i = ne[i]) {
        int j = e[i];
        if (!st[j]) {
            path.push_back(node[j]);
            dfs(j, sum + node[j]);
            path.pop_back();
        }
    }
}

inline void solution() {
    // 初始化
    idx = 0;
    mm(h, -1);
    mm(st, false);
    cin >> n >> m >> weight;
    for (int i = 0; i < n; i ++ ) 
        cin >> node[i];
    for (int i = 0; i < m; i ++ ) {
        int a, b, cnt;
        cin >> a >> cnt;
        while (cnt -- ) {
            cin >> b;
            add(a, b);
        }
    }

    path.push_back(node[0]);
    dfs(0, node[0]);
    sort(res.begin(), res.end(), greater<vector<int>>());
    for (auto & r : res) {
        cout << r[0];
        for (int i = 1; i < r.size(); i ++ ) 
            cout << " " << r[i];
        cout << endl;
    }

}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}